home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Examples / DemoText / UTEDocument.h < prev   
Encoding:
Text File  |  1996-04-03  |  14.1 KB  |  424 lines  |  [TEXT/MPS ]

  1. // UTEDocument.h
  2. // Copyright © 1984-95 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UTEDOCUMENT__
  5. #define __UTEDOCUMENT__
  6.  
  7. //----------------------------------------------------------------------------------------
  8. // This separate unit for TE Documents is still an example and not a supported Building
  9. // Block. It provides a backing document for those times when you want to write your
  10. // TEView to external media. Remember, since its not a building block right now the
  11. // structure is subject to more than the usual amount of change. Let us know what you
  12. // think.
  13. //----------------------------------------------------------------------------------------
  14.  
  15. //----------------------------------------------------------------------------------------
  16. // This document can be built without printing support by changing the following flag
  17. //----------------------------------------------------------------------------------------
  18. #if !defined(UsingDemoTextPrinting)
  19. #define UsingDemoTextPrinting 1
  20. #endif
  21.  
  22.  
  23. #if qPowerTalk
  24.     #ifndef __UMAILABLEDOCUMENT__
  25.     #include "UMailableDocument.h"
  26.     #endif
  27. #else
  28.     #ifndef __UFILEBASEDDOCUMENT__
  29.     #include "UFileBasedDocument.h"
  30.     #endif
  31. #endif
  32.  
  33. #ifndef __UTEVIEW__
  34. #include "UTEView.h"
  35. #endif
  36.  
  37.  
  38. const unsigned long kTextFileType = 'TEXT';        // Standard file-type code for saved disk
  39.                                                 // files -- uses standard text files 
  40.  
  41. const unsigned long kScrapType = 'TEXT';        // Standard scrap-type code for
  42.                                                 // WriteToScrap
  43.  
  44. const ResNumber kWindowRsrcID = 1004;            // 'view' template for a DemoText window 
  45.  
  46. const ResNumber kViewRsrcID = 1005;                // 'view' template for a DemoText view 
  47.  
  48.  
  49. //----------------------------------------------------------------------------------------
  50. // Menu numbers 
  51. //----------------------------------------------------------------------------------------
  52.  
  53. const short mFont = 10;
  54.  
  55.  
  56. //----------------------------------------------------------------------------------------
  57. // Command numbers 
  58. //----------------------------------------------------------------------------------------
  59.  
  60. const CommandNumber cWidthSuperView = 701;            // View-width-determination commands 
  61. const CommandNumber cWidthView = 702;
  62. const CommandNumber cWidthOnePage = 703;
  63.  
  64. const CommandNumber cHeightSuperView = 704;            // View-height-determination commands 
  65. const CommandNumber cHeightPages = 705;
  66. const CommandNumber cHeightText = 706;
  67. const CommandNumber cHeightConst = 707;
  68.  
  69. const CommandNumber cJustForceLeft = 708;            // Justification commands 
  70. const CommandNumber cJustCenter = 709;
  71. const CommandNumber cJustRight = 710;
  72. const CommandNumber cJustSystem = 711;
  73.  
  74. //  Command numbering scheme:
  75. //  styles    = 720-729
  76. //  sizes    = 800-899
  77. //  just    = 730-739
  78. //  fonts    = 740-749
  79. //  hiers    = 750-759
  80. //  colors    = 760-769
  81.  
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // Command numbers for typestyle attributes 
  85. //----------------------------------------------------------------------------------------
  86.  
  87. const CommandNumber cPlainText = 720;
  88. const CommandNumber cBold = 721;
  89. const CommandNumber cItalic = 722;
  90. const CommandNumber cUnderline = 723;
  91. const CommandNumber cOutline = 724;
  92. const CommandNumber cShadow = 725;
  93. const CommandNumber cCondense = 726;
  94. const CommandNumber cExtend = 727;
  95.  
  96.  
  97. //----------------------------------------------------------------------------------------
  98. // Command numbers for font-size commands 
  99. //----------------------------------------------------------------------------------------
  100.  
  101. const CommandNumber cSizeChange = 800;
  102. const CommandNumber cSizeBase = 800;
  103. const CommandNumber cSizeMin = 809;
  104. const CommandNumber cSizeMax = 896;
  105. const CommandNumber cSizeOther = 897;
  106.  
  107. //----------------------------------------------------------------------------------------
  108. // 801-897 reserved for font sizes 1-97 pts. 
  109. //----------------------------------------------------------------------------------------
  110.  
  111. const CommandNumber cSizeGrow = 898;
  112. const CommandNumber cSizeShrink = 899;
  113.  
  114.  
  115. //----------------------------------------------------------------------------------------
  116. // Command numbers to cover other stylistic changes 
  117. //----------------------------------------------------------------------------------------
  118.  
  119. const CommandNumber cJustChange = 730;
  120. const CommandNumber cFontChange = 731;
  121.  
  122.  
  123. //----------------------------------------------------------------------------------------
  124. // Command numbers for the hierarchial menu 
  125. //----------------------------------------------------------------------------------------
  126.  
  127. const CommandNumber cStyle = 750;
  128. const CommandNumber cSize = 751;
  129. const CommandNumber cFont = 752;
  130. const CommandNumber cColor = 753;
  131.  
  132.  
  133. //----------------------------------------------------------------------------------------
  134. // Command numbers for changing colors 
  135. //----------------------------------------------------------------------------------------
  136.  
  137. const CommandNumber cColorChange = 760;
  138. const CommandNumber cColorText = 761;
  139. const CommandNumber cColorBackground = 762;
  140.  
  141.  
  142. //----------------------------------------------------------------------------------------
  143. // Constant for staggering windows 
  144. //----------------------------------------------------------------------------------------
  145.  
  146. const short kStaggerAmount = 16;
  147.  
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // Constant for amount to relative size text selection 
  151. //----------------------------------------------------------------------------------------
  152.  
  153. const short kRelSizeAmount = 4;
  154.  
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // Constants for the text specs resource 
  158. //----------------------------------------------------------------------------------------
  159.  
  160. const ResType    kTextSpecsRsrcType = 'SPEC';
  161. const ResNumber kTextSpecsRsrcID = 1;
  162.  
  163.  
  164. //----------------------------------------------------------------------------------------
  165. // Constants for the text style resource 
  166. //----------------------------------------------------------------------------------------
  167.  
  168. const ResType     kTextStyleRsrcType = 'STYL';
  169. const ResNumber kStylesRsrcID = 1;
  170. const ResNumber kElementsRsrcID = 2;
  171.  
  172.  
  173. //----------------------------------------------------------------------------------------
  174. // Constants for the prompts CString list 
  175. //----------------------------------------------------------------------------------------
  176. const ResNumber kPromptsRsrcID = 1005;
  177. const short kColTextPrompt = 1;
  178. const short kColBackPrompt = 2;
  179.  
  180. #if qPowerTalk
  181. const short kReplySpacer = 3;
  182. const ResNumber kContentNotExtracted = 1017;
  183. const ResNumber kSnapshotNotExtracted = 1018;
  184. #endif
  185.  
  186. const ResNumber kFileTooBig = 1000;                    // The 'File is too large' alert 
  187.  
  188.  
  189. const ResNumber kHierDisplayedMBar = 131;            // Displayed menus on hier. menu system 
  190. const ResNumber kNonHierDisplayedMBar = 128;        // Displayed menus on non-hier. system 
  191.  
  192. const short kHierMenuOffset = 1000;                // Offset added to non-hier menu cmds to
  193.                                                 // get the right number 
  194.  
  195.  
  196. //============================================================================================
  197. // Data read from or written to disk files or exchanged via clip must be built to use the same
  198. // alignment. We choose to center on mac68K alignment. In your application you may choose any
  199. // data alignment that you wish, so long as both your PPC and 68K code agree on it.
  200. //============================================================================================
  201. #if PRAGMA_ALIGN_SUPPORTED
  202. #pragma options align=mac68k
  203. #endif
  204.  
  205. //----------------------------------------------------------------------------------------
  206. // TextSpecs: Additional document specifications
  207. //----------------------------------------------------------------------------------------
  208. struct TextSpecs
  209. {                                                
  210. public:
  211.     // constructors
  212.     inline TextSpecs() {}
  213.  
  214.     inline TextSpecs(const TextSpecs& copyTextSpecs) :
  215.         theTextFont(copyTextSpecs.theTextFont), 
  216.         theTextFace(copyTextSpecs.theTextFace), 
  217.         theTextSize(copyTextSpecs.theTextSize), 
  218.         theTextColor(copyTextSpecs.theTextColor), 
  219.         theJustification(copyTextSpecs.theJustification), 
  220.         theBackColor(copyTextSpecs.theBackColor) {}
  221.  
  222.     // Assignment operator
  223.  
  224.     inline TextSpecs& operator =(const TextSpecs& aTextSpecs);
  225.  
  226.     //----------------------------------------------------------------------------------------
  227.     // data members
  228.     //----------------------------------------------------------------------------------------
  229. public:
  230.     CStr255 theTextFont;
  231.     Style theTextFace;
  232.     short theTextSize;
  233.     CRGBColor theTextColor;
  234.     short theJustification;                        // record justification 
  235.     CRGBColor theBackColor;                        // Window's background color 
  236. };
  237.  
  238. typedef TextSpecs *TextSpecsPtr, **TextSpecsHdl;
  239.  
  240. #if PRAGMA_ALIGN_SUPPORTED
  241. #pragma options align=reset
  242. #endif
  243. //============================================================================================
  244. //============================================================================================
  245.  
  246.  
  247. inline TextSpecs& TextSpecs::operator = (const TextSpecs& aTextSpecs)
  248. {
  249.     MABlockMove(&aTextSpecs.theTextFont, &theTextFont, sizeof(TextSpecs));
  250.     
  251.     return *this;
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. // External and forward class declarations.
  256. //----------------------------------------------------------------------------------------
  257.  
  258. class TTEView;
  259. class TFile;
  260.  
  261.  
  262. //----------------------------------------------------------------------------------------
  263. // TTEDocument
  264. //----------------------------------------------------------------------------------------
  265.  
  266. #if qPowerTalk
  267. class TTEDocument : public TMailableDocument
  268. #else
  269. class TTEDocument : public TFileBasedDocument
  270. #endif
  271. {
  272.  
  273.     MA_DECLARE_CLASS;
  274.  
  275. public:
  276.     //------------------------------------------------------------------------------------
  277.     // Initialization and freeing 
  278.     //------------------------------------------------------------------------------------
  279.  
  280.     TTEDocument();
  281.     
  282.     virtual void ITEDocument(TFile* itsFile,
  283.                                     const OSType itsScrapType,
  284.                                     ResNumber itsViewResourceID);
  285.         // Initialization method for TTEDocument. 
  286.  
  287.     virtual ~TTEDocument();
  288.  
  289.     virtual void DoInitialState();
  290.  
  291.     virtual void FreeData();
  292.  
  293.  
  294.     //------------------------------------------------------------------------------------
  295.     // Filing 
  296.     //------------------------------------------------------------------------------------
  297.  
  298.     virtual void DoNeedDiskSpace(TFile* itsFile,
  299.                                         long& dataForkBytes,
  300.                                         long& rsrcForkBytes);
  301.  
  302.     virtual void DoRead(TFile* aFile, Boolean forPrinting);
  303.  
  304.     virtual void DoWrite(TFile* aFile, Boolean makingCopy);
  305.  
  306. #if qPowerTalk
  307.     //------------------------------------------------------------------------------------
  308.     // PowerTalk Support 
  309.     //------------------------------------------------------------------------------------
  310.  
  311.     virtual void AddStandardMailContent(Boolean& okToSend);
  312.  
  313.     virtual Boolean ReadStandardMailContent();
  314.  
  315.     virtual Boolean ReadNativeMailContent();
  316.  
  317.     virtual Boolean ReadSnapshotMailContent();
  318.  
  319.     virtual void SetReplyContents(TDocument* replyToDoc);
  320.  
  321.     virtual void ImageDocumentForLetter(Boolean inColor);
  322. #endif // qPowerTalk
  323.  
  324.     //------------------------------------------------------------------------------------
  325.     // Making views and windows 
  326.     //------------------------------------------------------------------------------------
  327.  
  328.     virtual void DoMakeViews(Boolean forPrinting);
  329.  
  330.  
  331.     //------------------------------------------------------------------------------------
  332.     // Command processing 
  333.     //------------------------------------------------------------------------------------
  334.  
  335.     virtual void DoMenuCommand(CommandNumber aCommandNumber);
  336.  
  337.     virtual void DoSetupMenus();
  338.  
  339.  
  340.     //------------------------------------------------------------------------------------
  341.     // Auxiliary routines 
  342.     //------------------------------------------------------------------------------------
  343.  
  344.     virtual void ChangeBackColor(const CRGBColor& newColor);
  345.  
  346.     virtual void SetSpecStyle();
  347.  
  348.     virtual void ShowReverted();
  349.         // When the user reverts a document, this is called after reading the old document
  350.         // and before displaying it. Causes the reverted font specs to be installed. 
  351.  
  352. protected:
  353.     void DoJustChange(CommandNumber aCommandNumber);
  354.  
  355.     void DoStyleChange(CommandNumber aCommandNumber);
  356.  
  357.     void DoColTextChange();
  358.  
  359.     void DoColBackChange();
  360.  
  361.     void InstallChangedDeterminer(VHSelect vhs, SizeDeterminer sd);
  362.  
  363.     void DoWidthChange(CommandNumber aCommandNumber);
  364.  
  365.     void DoHeightChange(CommandNumber aCommandNumber);
  366.  
  367.     //----------------------------------------------------------------------------------------
  368.     // data members
  369.     //----------------------------------------------------------------------------------------
  370. public:
  371.     TextSpecs fTextSpecs;                        // Specifies properties of the text 
  372.     TTEView* fTEView;                            // The view which displays the text 
  373.     Handle fDocText;                            // The text owned by the document 
  374.     TEStyleHandle fStyles;                        // Style handle, if any 
  375.     STHandle fElements;                            // Handle to element array, if any 
  376.     ResNumber fViewResourceID;                    // ID of 'view' resource
  377.     
  378.     //----------------------------------------------------------------------------------------
  379.     // static data members
  380.     //----------------------------------------------------------------------------------------
  381. public:
  382.     static TextSpecs gDefaultSpecs;
  383.         // Text specs as default for new documents 
  384.  
  385. };
  386.  
  387.  
  388. class TJustCommand : public TCommand
  389. {
  390.  
  391.     MA_DECLARE_CLASS;
  392.  
  393. public:
  394.     TJustCommand();
  395.         // Puts a newly created TJustCommand into a known state. Subclasses should
  396.         // override it and call INHERITED. Typically used to put the object into a state
  397.         // where it can be safely FREED. 
  398.     
  399.     virtual ~TJustCommand();
  400.         // Destructor
  401.  
  402.     virtual void IJustCommand(TTEView* itsTEView, short itsNewJust);
  403.  
  404.     virtual void DoIt();
  405.  
  406.     virtual void UndoIt();
  407.  
  408.     //----------------------------------------------------------------------------------------
  409.     // data members
  410.     //----------------------------------------------------------------------------------------
  411. public:
  412.     TTEView* fTEView;
  413.     short fOldJust;
  414.     short fNewJust;
  415. };
  416.  
  417. // ---------------------------------------------------------------------------------------
  418. void InitUTEDocument();
  419. //  Initialize TEDocument unit. 
  420.  
  421. #endif
  422.  
  423.  
  424.